//
//  KRReadList.m
//  cookBook
//
//  Created by kuroken on 16/1/12.
//  Copyright © 2016年 kuroken. All rights reserved.
//

#import "KRReadList.h"
#import <MJExtension.h>
#import "__lldb_autogen_nspair.h"
#import "KRConst.h"

@implementation KRReadList
+ (void)load
{
    [KRReadList mj_setupReplacedKeyFromPropertyName:^__lldb_autogen_nspair *{
        return (__lldb_autogen_nspair *)@{
                                          @"title" : @"Title",
                                          @"img" : @"Img",
                                          @"url" : @"Url",
                                          @"intro" : @"Intro"
                                          };
    }];
    
}

/* 
 *  Url = haodourecipe://haodou.com/opentopic/?url=http%3A%2F%2Fm.haodou.com%2Ftopic-328764.html&id=328764
          haodourecipe://haodou.com/openurlid/?id=552045&_wt=3
 */
- (void)setUrl:(NSString *)url
{
    _url = [[url stringByRemovingPercentEncoding] copy];
//    NSLog(@"%@", _url);
    if ([url containsPartString:@"topic"]) {
        NSString *searchString = @"id=";
        NSRange range = [url rangeOfString:searchString];
        _topicID = [url substringFromIndex:range.location + range.length];
    } else if ([url containsPartString:@"urlid"]) {
        NSString *searchString = @"?id=";
        NSRange range = [url rangeOfString:searchString];
        NSUInteger loc = range.location + range.length;
        
        NSRange range_and = [url rangeOfString:@"&"];
        NSUInteger len = range_and.location - loc;
        
        _shareID = [url substringWithRange:NSMakeRange(loc, len)];
    } else {
        NSString *searchString = @"url=";
        NSRange range = [_url rangeOfString:searchString];
        _url = [_url substringFromIndex:range.location + range.length];
    }
}

@end
